package cn.huangsm.advance.thread;

/**
 * 伪造支付逻辑
 * 包含提交支付请求------第三方支付通道调用
 * @author huang
 * @PACKAGE_NAME cn.huangsm.advance.thread
 * @PROJECT_NAME advance-code
 * @date 2019/1/10
 */
public class PayMentService {
    /**
     * 提交支付请求
     * @param request
     * @return
     * @throws InterruptedException
     */
    public String submitPay(PayMentRequest request) throws InterruptedException {
        System.out.println("开始校验支付请求参数");
        Thread.sleep(2000);
        return doPay(request);
    }

    /**
     * 调用第三方支付通道
     * @param request
     * @return
     * @throws InterruptedException
     */
    private String doPay(PayMentRequest request) throws InterruptedException {
        System.out.println("开始处理支付请求:" + request);
        Thread.sleep(3000);
        return "success";
    }

    public static void main(String[] args) throws InterruptedException {
        Long start= System.currentTimeMillis();
        PayMentService payMentService=new PayMentService();
        PayMentRequest payMentRequest=new PayMentRequest();
        payMentRequest.setPayMethod(1);
        payMentRequest.setTotalFee(100);
        payMentRequest.setReturnUrl("http://www.huangsm.com/pay");
        payMentService.submitPay(payMentRequest);
        long end = System.currentTimeMillis();
        System.out.println("处理时间:"+(end-start));
    }
}
